<?php

!defined('IN_APP') && exit('Access Denied');
include APP_ROOT . "/lib/Client.php";

class messagemodel {

    var $db;
    var $base;
    var $sms;

    function __construct(&$base) {
        $this->base = $base;
        $this->db = $base->db;
        $this->sms = new Client(SMS_SERVER, SMS_USER, SMS_PW);
        $this->sms->pszSubPort = SMS_PORT;
        $this->sms->setOutgoingEncoding(CONTENT_CHARSET);
    }

    /**
     * 发送短消息
     * @param type $mobilelist
     * @param type $content
     * @param type $touid 
     */
    function addsms($mobilelist, $content, $cid=0) {
        $ret = $this->sms->sendSMS($mobilelist, $content);
        $sql = "INSERT INTO " . DB_TABLEPRE . "smsmessage(`cid`,`mobile`,`content`,`time`) VALUES ";
        foreach ($mobilelist as $mobile) {
            $sql .="($cid,'$mobile','$content',{$this->base->time}),";
        }
        $this->db->query(substr($sql, 0, -1));
    }

}

?>